<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let a =''
      let b =''
      let c =''

      // console.log(/\?(.+)&/.exec(a)[1].substring(5));
      // console.log(/\?(.+)&/.exec(a));
      // let c = a.split("?")
      // console.log(getCodeFn(b,"code"))
      // console.log(toDelCodeFn(b),toDelCodeFn(a),"123")

      // console.log(new RegExp("(?=code=).*?(?=&)").match(a),getURl(b));
      // toDelCodeFn(a)
      // toDelCodeFn(b)
      toDelCodeFn(a);
      function getURl(url) {
        let arr = url.split("&");
        console.log(arr, "24");
        let newarr = arr.filter(
          (item) => !(item.includes("code=") || item.includes("state="))
        );
        return newarr.join("");
      }

      function getCodeFn(url, code) {
        url = url + "";
        let regstr = "/(\\?|\\&)" + code + "=([^\\&]+)/";
        let reg = eval(regstr);
        let result = url.match(reg);
        console.log(result, "result");
        if (result && result[2]) {
          return result[2];
        }
      }

      function toDelCodeFn(url) {
        let reg3 = new RegExp(/(?=\?code=).*?(?=)/g);
        let reg4 = new RegExp(/(?=code=).*?(?=&)/g);
        let reg2 = new RegExp(/(?=state=).*?(?=#)/g);
        let str = "&state=xxx";
        let str2 = "&state=";
        let newstr = url;
        // if(url.includes('code=')){
        console.log(url.match(reg3), url.match(reg4));
        console.log(url.match(reg2));
        //     if(url.match(reg)&&url.match(reg)[0]){
        //         newstr = url.replace(reg,"").replace("?","")
        //     }
        if (url.match(reg4) && url.match(reg4)[0]) {
          newstr = url
            .replace(/(?=\?code=).*?(?=#\/)/g, "")
            .replace(/(?=code=).*?(?=&)/g, "")
            .replace(/&state=xxx/g, "")
            .replace(/&state=/g, "")
            .replace(/&+$/g, "");
        }
        // }
        console.log(newstr, "newstr");
        // return newstr
      }
    </script>
  </body>
</html>
